<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Genre extends MY_Controller {
    
    public function __construct()
    {
        parent::__construct();
    }

	/**
	 * Index Page for this controller.
	 *
	 * Maps to the following URL
	 * 		http://example.com/index.php/welcome
	 *	- or -  
	 * 		http://example.com/index.php/welcome/index
	 *	- or -
	 * Since this controller is set as the default controller in 
	 * config/routes.php, it's displayed at http://example.com/
	 *
	 * So any other public methods not prefixed with an underscore will
	 * map to /index.php/welcome/<method_name>
	 * @see http://codeigniter.com/user_guide/general/urls.html
	 */
	public function index()
	{
		redirect('admin_panel/genre/main');
	}
    
    public function main()
    {
        $crud = new grocery_CRUD();
        $crud->set_table('genres');
        $crud->set_subject('Song Genres');
        
        $crud->where('genres.deleted',0);
        $crud->order_by('genres.name');
        
        $crud->add_action('Remove Genre',site_url('html/images/soft_delete.png'),'admin_panel/genre/delete','confirm-delete');
        
        $crud->unset_columns('remarks','deleted');
        $crud->unset_fields('deleted');
        $crud->unset_delete();
        
        $crud->set_rules('name','Genre Name','required');
        
        $output = $crud->render();
        $this->load->vars($output);
        
        $this->load->view('admin_panel/genre/main');
    }
    
    public function delete($id)
    {
        $param = array(
            'table'     =>  'genres',
            'fields'    =>  array('deleted' => 1),
            'condition' =>  array('id' => $id)
        );
        if($this->general_model->_save_record($param))
        {
            $this->session->set_flashdata('success_message','Genre record removed.');
            redirect('admin_panel/genre/main');
        }
    }
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */